<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./template.xhtml">

            <ui:define name="title">
                Quản trị trang giới thiệu
            </ui:define>

            <ui:define name="content">
                <h:form>
                    <h:panelGrid columns="2">
                        Tên dịch vụ:
                        <p:inputText value="#{serviceIntroBean.selected.serviceTitle}"/>

                        Ảnh đại điện
                        <p:inputText value="#{serviceIntroBean.selected.url}"/>
                        
                        Mô tả ngắn
                        <p:inputTextarea value="#{serviceIntroBean.selected.shortDescription}"/>

                        Mô tả dài
                        <p:inputTextarea value="#{serviceIntroBean.selected.longDescription}"/>
                        <f:facet name="footer">  
                            <p:commandButton ajax="false" value="Thêm mới" rendered="#{!serviceIntroBean.edit}" action="#{serviceIntroBean.create()}"/>
                            <p:commandButton ajax="false" value="Cập nhật" rendered="#{serviceIntroBean.edit}" action="#{serviceIntroBean.edit()}"/>
                            <p:commandButton ajax="false" value="Hủy bỏ" immediate="true" action="#{serviceIntroBean.resetToCreateForm()}"/>
                        </f:facet>
                    </h:panelGrid>
                </h:form>

                <br/>

                <h:form>

                    <p:dataTable id="table" value="#{serviceIntroBean.list}" var="item" paginator="#{serviceIntroBean.list.size() >20}" rows="20" 
                                 selection="#{serviceIntroBean.selectedList}" selectionMode="multiple" resizableColumns="true"
                                 >

                        <f:facet name="header">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{serviceIntroBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="DeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <f:facet name="footer">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{serviceIntroBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="DeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <p:column headerText="Đầu số" sortBy="#{item.serviceTitle}">
                            #{item.serviceTitle}
                        </p:column>
                        <p:column headerText="Mô tả ngắn" sortBy="#{item.shortDescription}">
                            #{item.shortDescription}
                        </p:column>
                        <p:column headerText="Mô tả dài" sortBy="#{item.longDescription}">
                            #{item.longDescription}
                        </p:column>
                        
                        <p:column headerText="Ảnh">
                            #{item.url}
                            <!--<img src="#{item.url}" height="100" width="100"/>-->
                        </p:column>
                    </p:dataTable>

                    <p:confirmDialog message="Bạn muốn xóa các bản ghi đã chọn?"  
                                     header="Xác nhận" severity="alert" widgetVar="DeleteConfirm">  

                        <p:commandButton update="table" value="Có" oncomplete="DeleteConfirm.hide()"  
                                         action="#{serviceIntroBean.remove()}"/>
                        <p:commandButton value="Không" onclick="DeleteConfirm.hide()" type="button" />   

                    </p:confirmDialog>

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
